﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Lucene.Net.Analysis;
using Lucene.Net.Search;
using LuceneStore = Lucene.Net.Store;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.QueryParsers;
using Lucene.Net.Documents;
using Lucene.Net.Search.Highlight;
using Lucene.Net.Analysis.PanGu;

using XMK.Tadong.Model;
using XMK.Framework.Model;
using XMK.Utils;
using PanGu;

namespace XMK.Tadong.DataSearch.Data
{
    public class FileSearchData
    {
        private string _filePath;

        public FileSearchData(string indexFilePath)
        {
            _filePath = indexFilePath;
        }

        /// <summary>
        /// 文档搜索
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <param name="sort">排序-可以为空</param>
        /// <param name="pageInfo">分页</param>
        /// <returns></returns>
        public int[] SearchFileList(LuceneQuery query, LuceneSort sort, PageInfo pageInfo)
        {
            int[] hits = null;
            int recordCount;
            LuceneAccess luceneHelper = new LuceneAccess(_filePath);
            if (sort != null)
                hits = luceneHelper.ExecuteQuery(query, sort,
                    pageInfo.CurrentPage, pageInfo.PageSize, out recordCount);
            else
                hits = luceneHelper.ExecuteQuery(query, 
                    pageInfo.CurrentPage, pageInfo.PageSize, out recordCount);
            pageInfo.Records = recordCount;
            return hits;

        }

        
    }

    
}
